/* 项目入口文件 */

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './assets/css/global.css' /* 全局样式表 */
import TreeTable from 'vue-table-with-tree-grid'

//移除控制台passive警告
import 'default-passive-events'

//富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
//富文本编辑器对应样式文件
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme

//导入顶部进度条Nprogress对应的JS、CSS包
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'

import axios from 'axios'
//配置请求根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'

//请求拦截器，在请求发出之前设置一些信息，再发送请求
axios.interceptors.request.use(config => {
  //在request拦截器中，展示进度条Nprogress.start()
  Nprogress.start()
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
});

//在response拦截器中，隐藏进度条Nprogress.done()
axios.interceptors.response.use(config => {
  Nprogress.done()
  return config
})

Vue.prototype.$http = axios

Vue.config.productionTip = false

Vue.component('tree-table',TreeTable);

//将富文本编辑器注册为全局可用的组件
Vue.use(VueQuillEditor);

//全局时间过滤器
Vue.filter('dateFormat',function(originVal){
  let dt = new Date(originVal)
  let y = dt.getFullYear()
  let m = (dt.getMonth() + 1 + '').padStart(2,'0')
  let d = (dt.getDate() + '').padStart(2,'0')
  let hh = (dt.getHours() + '').padStart(2,'0')
  let mm = (dt.getMinutes() + '').padStart(2,'0')
  let ss = (dt.getSeconds() + '').padStart(2,'0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
